<style>
	.category-button{font-size:0.9em;font-weight:bold;cursor:pointer}
	.category-button:hover{}
</style>

<div class="section">
	<div class="section-title">Service</div>
	<div class="content">
   		<table>
        	<thead>
            	<tr>
                	<th>Service name</th>
                    <th><?php echo $this->document->text['text_control']?></th>
                </tr>
            </thead>
        	<tbody>
<?php
	foreach($category as $item)
    {
?>
        		<tr>
            		<td>
                    	<a href="?route=soft/product&sitemapid=<?php echo $item['sitemapid']?>"><?php echo $item['sitemapname']?></a>
                    </td>
                    <td align="center">
                        <a class="category-button" onclick="addCategory('<?php echo $item['sitemapid']?>')">Add child</a> 
                        <a class="category-button" onclick="editCategory('<?php echo $item['sitemapid']?>')"><?php echo $this->document->text['button_edit']?></a> 
                        <a class="category-button" onclick="removeCategory('<?php echo $item['sitemapid']?>')">Remove</a> 
                	</td>
            	</tr>
<?php
	}
?>
			</tbody>
        </table>
		<a class="button" onclick="addCategory('')">Add service</a>
        <form id="fcategory" method="post" style="display:none">
            <input type="hidden" id="Position" name="Position" />
            
        	<p>
            	
                <input type="hidden" class="text" id="CatelogyID" name="CatelogyID" /><br />
                <label>Category name</label><br />
                <input type="text" class="text" id="CategoryName" name="CategoryName" /><br />
                <label>Parent</label>
                <select id="CategoryParent" name="CategoryParent">
                	<option value="service">Root</option>
<?php
	foreach($category as $item)
    {
?>
					<option value="<?php echo $item['sitemapid']?>"><?php echo $item['sitemapname']?></option>
<?php
	}
?>
                </select><br />
                <a class="button" onclick="saveCategory()">Save</a>
            </p>
        </form>
    </div>
</div>
<script language="javascript">
function saveCategory()
{
	if( $("#CategoryName").val() !="")
	{
		$.blockUI({ message: "<h1>Please wait...</h1>" }); 
		$.post("?route=soft/category/save", 
			   $("#fcategory").serialize(),
			   function(data)
			   {
				   window.location.reload();
				}
			   );
		
	}
}
function addCategory(parent)
{
	$.blockUI({ message: "<h1>Please wait...</h1>" }); 
	$('#fcategory').show('slow');
	$('#CatelogyID').val('');
	$("#CategoryParent").val(parent);
	$('#CategoryName').val('');
	$.unblockUI(); 
}
function editCategory(categoryid)
{
	$('#fcategory').show('slow');
	$.getJSON("?route=soft/category/getCategory&categoryid="+categoryid, 
			function(data) 
			{
				//alert(data.subimage.imagepreview);
				$.blockUI({ message: "<h1>Please wait...</h1>" }); 
				$("#CatelogyID").val(data.category.sitemapid);
				$("#CategoryName").val(data.category.sitemapname);
				$("#CategoryParent").val(data.category.sitemapparent);
				$("#Position").val(data.category.position);
				$.unblockUI(); 
			});
}

function removeCategory(categoryid)
{
	var answer = confirm("Are you want to delete")
	if(answer)
		$.ajax({
			url: "?route=soft/category/removeCategory&categoryid="+categoryid,
			cache: false,
			success: function(html){
				if(html=="true")
					window.location.reload();
				else
					alert("Can't delete because this category contained some products!")
			}
		});
}
</script>